<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="客户号" prop="userInfoId">
        <el-input
          v-model="queryParams.userInfoId"
          placeholder="请输入客户号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-date-picker clearable
          v-model="queryParams.date"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="联络方式" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入联络方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="客情状态" prop="contactStatus">
        <el-select v-model="queryParams.contactStatus" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="推荐内容" prop="recommend">
        <el-input
          v-model="queryParams.recommend"
          placeholder="请输入推荐内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="效果反馈" prop="result">
        <el-input
          v-model="queryParams.result"
          placeholder="请输入效果反馈"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="跟进日期" prop="followDate">
        <el-date-picker clearable
          v-model="queryParams.followDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择跟进日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="跟进方式" prop="followWay">
        <el-input
          v-model="queryParams.followWay"
          placeholder="请输入跟进方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="跟进意向产品/服务" prop="followIntention">
        <el-input
          v-model="queryParams.followIntention"
          placeholder="请输入跟进意向产品/服务"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="contactRemark">
        <el-input
          v-model="queryParams.contactRemark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['kycinfo:contact:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['kycinfo:contact:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['kycinfo:contact:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['kycinfo:contact:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="contactList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" width="55" align="center" label="序号" />
      <el-table-column label="客户号" align="center" prop="userInfoId"/>
      <el-table-column label="日期" align="center" prop="date" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="联络方式" align="center" prop="phone" width="150" />
      <el-table-column label="客情状态" align="center" prop="contactStatus" />
      <el-table-column label="推荐内容" align="center" prop="recommend" />
      <el-table-column label="效果反馈" align="center" prop="result" />
      <el-table-column label="跟进日期" align="center" prop="followDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.followDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="跟进方式" align="center" prop="followWay" />
      <el-table-column label="跟进意向产品/服务" align="center" prop="followIntention" />
      <el-table-column label="备注" align="center" prop="contactRemark" />
<!--      <el-table-column label="备注" align="center" prop="remark" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['kycinfo:contact:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['kycinfo:contact:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改 联络情况 对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="客户号" prop="userInfoId">
          <el-input v-model="form.userInfoId" placeholder="请输入客户号" />
        </el-form-item>
        <el-form-item label="日期" prop="date">
          <el-date-picker clearable
            v-model="form.date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="联络方式" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入联络方式" />
        </el-form-item>

        <el-form-item label="客情状态" prop="contactStatus">
          <el-select v-model="form.contactStatus" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="推荐内容" prop="recommend">
          <el-input v-model="form.recommend" placeholder="请输入推荐内容" />
        </el-form-item>
        <el-form-item label="效果反馈" prop="result">
          <el-input v-model="form.result" placeholder="请输入效果反馈" />
        </el-form-item>
        <el-form-item label="跟进日期" prop="followDate">
          <el-date-picker clearable
            v-model="form.followDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择跟进日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="跟进方式" prop="followWay">
          <el-input v-model="form.followWay" placeholder="请输入跟进方式" />
        </el-form-item>
        <el-form-item label="跟进意向产品/服务" prop="followIntention">
          <el-input v-model="form.followIntention" placeholder="请输入跟进意向产品/服务" />
        </el-form-item>
        <el-form-item label="备注" prop="contactRemark">
          <el-input v-model="form.contactRemark" placeholder="请输入备注" />
        </el-form-item>
<!--        <el-form-item label="备注" prop="remark">-->
<!--          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listContact, getContact, delContact, addContact, updateContact } from "@/api/kycinfo/contact";

export default {
  name: "Contact",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // kyc客户联络情况表格数据
      contactList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      options: [{
        value: '重要熟悉',
        label: '重要熟悉'
      }, {
        value: '重要不熟悉',
        label: '重要不熟悉'
      }, {
        value: '熟悉不重要',
        label: '熟悉不重要'
      }, {
        value: '不熟悉不重要',
        label: '不熟悉不重要'
      }],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userInfoId: null,
        date: null,
        phone: null,
        contactStatus: null,
        recommend: null,
        result: null,
        followDate: null,
        followWay: null,
        followIntention: null,
        contactRemark: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userInfoId: [
          { required: true, message: "客户号不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询kyc客户联络情况列表 */
    getList() {
      this.loading = true;
      listContact(this.queryParams).then(response => {
        this.contactList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        contactId: null,
        userInfoId: null,
        date: null,
        phone: null,
        contactStatus: null,
        recommend: null,
        result: null,
        followDate: null,
        followWay: null,
        followIntention: null,
        contactRemark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.contactId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加客户联络情况";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const contactId = row.contactId || this.ids
      getContact(contactId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改客户联络情况";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.contactId != null) {
            updateContact(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContact(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const contactIds = row.contactId || this.ids;
      this.$modal.confirm('是否确认删除客户号为"' + contactIds + '"的该条联络情况？').then(function() {
        return delContact(contactIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/contact/export', {
        ...this.queryParams
      }, `contact_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
